export default {
    name: "app",
    data() {
        return {
            // 获取的仓库信息列表
            warehouse_list: [],
            // 查询仓库的信息
            inquire: {
                warehouseId: '',
                warehouseName: '',
            },
            // 新增仓库的弹窗
            warehouseAddDialog: false,
            // 删除仓库的弹窗
            warehouseDeleteDialog: false,
            // 修改仓库的弹窗
            warehouseModifyDialog: false,
            // 操作仓库信息
            warehouse: {
                warehouseName: '',
                capacity: '',
            },
        }
    },
    created() {
        // this.$store.dispatch('get_current')
        this.get_warehouses()
    },
    methods: {
        // 获取所有仓库信息
        async get_warehouses() {
            const { data: res } = await this.$http.get('/gim/api/admin/manageWarehouse/selectWarehouse/allWarehouse');
            // console.log(res)
            // 获取成功
            if (res.code == 1)
                this.warehouse_list = res.response
            else if (res.code == 502)
                this.$store.commit('error', res.msg)
            else {
                this.$store.commit('error', res.response)
            }
        },
        // 条件查询仓库
        async serch_warehouse() {
            const inquire = this.$qs.parse(this.inquire)
            const { data: res } = await this.$http.post('/gim/api/admin/manageWarehouse/selectWarehouse/condition', inquire);
            // console.log(res)
            if (res.code == 1)
                this.warehouse_list = res.response
            else {
                this.$store.commit('error', res.response)
            }
        },
        // 跳转仓库详情
        warehouse_detail(item) {
            this.warehouse = this.$qs.stringify(item)
            this.$router.push({ path: "/warehouse_detail", query: { detail: this.warehouse } })
        },

        // 新增仓库
        async add_warehouse() {
            // 重置
            this.warehouse = {
                warehouseName: '',
                capacity: '',
            }
            if (this.warehouse.warehouseName == '' || this.warehouse.capacity == '') {
                this.$store.commit('error', '请完善仓库信息！')
            }
            else {
                // 将form表单数据转化为Json
                const warehouse = this.$qs.parse(this.warehouse)
                const { data: res } = await this.$http.post('/gim/api/admin/manageWarehouse/insertWarehouse', warehouse);
                if (res.code == 1) {
                    this.$store.commit('success', res.response)
                    this.get_warehouses()
                }
                else
                    this.$store.commit('error', res.response)
            }
            this.warehouseAddDialog = false
        },
        // 修改仓库信息
        open_modify_dialog(item) {
            // console.log(item)
            this.warehouseModifyDialog = true
            this.warehouse = item
        },
        async modify_warehouse() {
            const warehouse = this.$qs.parse(this.warehouse)
            const { data: res } = await this.$http.post('/gim/api/admin/manageWarehouse/updateWarehouse/' + this.warehouse.warehouseId, warehouse)
            // console.log(res)
            if (res.code == 1) {
                this.$store.commit('success', res.response)
            }
            if (res.code == 2) {
                this.$store.commit('error', res.response)
            }
            // 重置
            this.warehouse = {
                warehouseName: '',
                capacity: '',
            }
            this.warehouseModifyDialog = false
        },
        // 删除仓库
        open_delete_dialog(item) {
            this.warehouseDeleteDialog = true
            this.warehouse = item
        },
        async delete_warehouse() {
            // 调用接口
            const { data: res } = await this.$http.get('/gim/api/admin/manageWarehouse/deleteWarehouse/' + this.warehouse.warehouseId);
            // console.log(res)
            if (res.code == 1) {
                this.$store.commit('success', '删除仓库成功!')
                this.get_warehouses()
            }
            else
                this.$store.commit('error', '删除仓库失败!')
            // 重置
            this.warehouse = {
                warehouseName: '',
                capacity: '',
            }
            this.warehouseDeleteDialog = false
        },
    },
};